package simulations.factory;

import forces.Gravity;
import forces.Viscosity;
import forces.WallRepulsion;
import simulations.Simulation;

import java.util.Scanner;

/**
 * @author Zach Michaelov
 */
public class ForceFactory {
    /**
     * populates the Simulation with the appropriate Force specified by the Scanner
     *
     * @param line
     * @param sim
     * @return
     */
    public static void fromScanner(Scanner line, Simulation sim) {
        String type = line.next();
        if (type.equals("viscosity")) {
            sim.add(createViscosity(line));
        } else if (type.equals("gravity")) {
            sim.add(createGravity(line));
        } else if (type.equals("wall")) {
            sim.add(createWallRepulsion(line, sim));
        } else if (type.equals("centermass")) {
            createCenterMass(line, sim);
        }
    }
    /*
        static Helper methods
     */

    /**
     * creates a wall repulsion Force based on the text file data
     *
     * @param line the Scanner object we are using to read our model file
     * @return the new WallRepulsion Force
     */
    private static WallRepulsion createWallRepulsion(Scanner line, Simulation sim) {
        int wallID = line.nextInt();
        double magnitude = line.nextDouble();
        int exponentVal = line.nextInt();
        return new WallRepulsion(wallID, magnitude, exponentVal, sim);
    }

    /**
     * creates a gravitational Force based on the text file data
     *
     * @param line the Scanner object we are using to read our model file
     * @return the new Force of gravity
     */
    private static Gravity createGravity(Scanner line) {
        double direction = line.nextDouble();
        double magnitude = line.nextDouble();
        return new Gravity(direction, magnitude);
    }

    /**
     * creates a viscous Force based on the text file data
     *
     * @param line the Scanner object we are using to read our model file
     * @return the new Force of viscosity
     */
    private static Viscosity createViscosity(Scanner line) {
        double scalar = line.nextDouble();
        return new Viscosity(scalar);
    }

    /**
     * Sets the magnitude and exponent for the center-of-mass
     * Force for Entities in this Simulation
     *
     * @param line
     * @param sim
     */
    private static void createCenterMass(Scanner line, Simulation sim) {
        sim.setCenterOfMassMagnitude(line.nextDouble());
        sim.setCenterOfMassExpVal(line.nextDouble());

    }
}
